package com.tedu.startbooksstore.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tedu.startbooksstore.pojo.vo.BannerListItemVO;
import com.tedu.startbooksstore.service.IBannerService;
import com.tedu.startbooksstore.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图控制类
 * @author 敖朝浪
 */

@RestController
@Slf4j
@Api("0.4轮播图管理")
@RequestMapping("/banners")
public class BannerController {
    @Autowired
    IBannerService bannerService;


    @ApiOperationSupport(order = 410)
    @ApiOperation("删除轮播图")
    @PostMapping("/{id}/delete")
    //http://localhost:8080/banners/id/delete
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理删除轮播图请求");
        bannerService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperationSupport(order = 420)
    @ApiOperation("轮播图列表")
    @GetMapping("")
   // http://localhost:8080/banners
    public JsonResult<List<BannerListItemVO>> list(){
        log.debug("开始处理轮播图列表请求");
        List<BannerListItemVO> list = bannerService.list();
        return JsonResult.ok(list);
    }

}
